(function (vc) {
    vc.extends({
        data: {
            addStoreMsgInfo: {
                msgId: '',
                title: '',
                pageUrl: '',
            }
        },
        _initMethod: function () {
           
        },
        _initEvent: function () {
            vc.on('addStoreMsg', 'openAddStoreMsgModal', function () {
                $('#addStoreMsgModel').modal('show');
            });
        },
        methods: {
            addStoreMsgValidate() {
                return vc.validate.validate({
                    addStoreMsgInfo: $that.addStoreMsgInfo
                }, {
                    'addStoreMsgInfo.title': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "通知名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "128",
                            errInfo: "通知名称不能超过128位"
                        },
                    ],
                    'addStoreMsgInfo.pageUrl': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "消息内容不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "512",
                            errInfo: "消息内容超过512位"
                        },
                    ],
                });
            },
            saveStoreMsgInfo: function () {
                if (!$that.addStoreMsgValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                $that.addStoreMsgInfo.shopId = vc.getCurrentCommunity().shopId;

                vc.http.apiPost(
                    '/shopMsg.saveShopMsg',
                    JSON.stringify($that.addStoreMsgInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addStoreMsgModel').modal('hide');
                            $that.clearAddStoreMsgInfo();
                            vc.emit('storeMsgManage', 'listStoreMsg', {});
                            vc.toast("发布成功");
                            return;
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            clearAddStoreMsgInfo: function () {
                $that.addStoreMsgInfo = {
                    msgId: '',
                    title: '',
                    pageUrl: '',
                };
            }
        }
    });
})(window.vc);
